package com.yisu.expressway.manager.core.service.impl;

import com.yisu.expressway.ewf.entity.SpecificationGoods;
import com.yisu.expressway.manager.core.mapper.SpecificationGoodsMapper;
import com.yisu.expressway.manager.core.service.ISpecificationGoodsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by zj on 2017/4/25.
 */
@Service
public class SpecificationGoodsServiceImpl implements ISpecificationGoodsService {
    @Resource
    private SpecificationGoodsMapper specificationGoodsMapper;

    /**
     * 编辑规格商品信息
     *
     * @param specificationGoods
     * @return
     */
    @Override
    public boolean modifySpecificationGoods(SpecificationGoods specificationGoods) {
        try {
            SpecificationGoods entity = specificationGoodsMapper.selectBySpecificationGoodsInfo(specificationGoods);
            if (entity != null) {
                entity.setPrice(specificationGoods.getPrice());
                entity.setBazaarPrice(specificationGoods.getBazaarPrice());
                entity.setInventoryNum(specificationGoods.getInventoryNum());
                entity.setSalesVolume(specificationGoods.getSalesVolume());
                specificationGoodsMapper.updateByPrimaryKey(entity);
            } else {
                specificationGoodsMapper.insert(specificationGoods);
            }
            return true;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return false;
    }

    /**
     * 获取规格商品列表，通过商品编号及分类编号
     *
     * @param specificationGoods
     * @return
     */
    @Override
    public List<SpecificationGoods> getSpecificationGoodsListByGoodsNoAndCategoryCode(SpecificationGoods specificationGoods) {
        return specificationGoodsMapper.getSpecificationGoodsListByGoodsNoAndCategoryCode(specificationGoods);
    }

    /**
     * @param specificationGoods
     * @return
     */
    @Override
    public boolean modifySpecificationGoodsByCustom(SpecificationGoods specificationGoods) {
        return specificationGoodsMapper.updateByPrimaryKeySelective(specificationGoods)>0;
    }
}
